
angular.module('Demo')

.controller('Demo.DetailCtrl', ['$scope', 'imanDialog', function ($scope, imanDialog) {
    $scope.data = {
        singleMaster: {
            MOCode: '006',
            MOLotNumber: 'P2012',
            ItemMasterCode: 'ST021',
            ItemMasterName: '网拍',
            WorkName: '补土质检',
            Users: [{
                Name: '李红'
            }]
        },
        badDetail: [{
            BadType: '碰伤/划伤',
            BadPosition: '内12点',
            Description: '轻微划伤'
        }, {
            BadType: '孔边掉漆',
            BadPosition: '2/12点',
            Description: '面积不大'
        }, {
            BadType: 'PU发泡',
            BadPosition: 'T头',
            Description: ''
        }],
        badDetailInput: {
            BadType: '碰伤/划伤',
            BadPosition: '内12点',
            BadPositionValue: 6,
            Description: '轻微划伤'
        }
    };

    $scope.onBadPos = function (defect) {
        imanDialog.showList({
            title: '请选择碰伤/划伤位置',
            list: [
                { id: 0, name: 'T头' },
                { id: 1, name: '5/7点' },
                { id: 2, name: '3/9点' },
                { id: 3, name: '2/10点' },
                { id: 4, name: '12点' },
                { id: 5, name: '内6点' },
                { id: 6, name: '内12点' },
                { id: 7, name: '内3/9' },
                { id: 8, name: '内5/7' },
                { id: 9, name: '拍柄' }
            ],
            valueField: 'id',
            displayField: 'name',
            value: defect.BadPositionValue
        }).then(function (select) {
            defect.BadPositionValue = select.id;
            defect.BadPosition = select.name;
        });
    };

    var toast;
    $scope.showToast = function () {
        if (toast) {
            toast.hide();
        }
        toast = imanDialog.toast({
            message: '测试弹出提示信息',
            block: true,
            position: 'top',
            duration: false,
            backdropClickToClose: false,
            hardwareBackButtonClose: false
        });
    };
    $scope.hideToast = function () {
        if (toast) {
            toast.hide();
            toast = null;
        }
    };
    $scope.$on('$ionicView.beforeLeave', function () {
        if (toast) {
            toast.hide();
            toast = null;
        }
    });
}]);